﻿namespace AnyOffice.Components
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Web.UI;

    public class BasePage : Page
    {
        private SqlConnection conn;

        public void CloseConn()
        {
            if (this.conn!=null&&this.conn.State == ConnectionState.Open) this.conn.Close();
        }

        protected override void OnInit(EventArgs O)
        {
            base.OnInit(O);
            this.conn = new SqlConnection(ConfigManager.ConnectionString);
            this.ThemeWrite();
        }

        protected override void OnUnload(EventArgs O)
        {
            this.CloseConn();
            base.OnUnload(O);
        }

        public string ShowError(string content)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg error\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<center><input type=\"button\" class=\"BigButton\" value=\"返回\" onclick=\"history.back();\"></center>");
            return builder.ToString();
        }

        public string ShowError(string content, string url)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg error\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<br><center><input type=\"button\" class=\"BigButton\" value=\"返回\" onclick=\"window.location='" + url + "';\"></center>");
            return builder.ToString();
        }

        public string ShowErrorClose(string content)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg error\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<center><input type=\"button\" class=\"BigButton\" value=\"关闭\" onclick=\"self.close();\"></center>");
            return builder.ToString();
        }

        public string ShowErrorNoNav(string content)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg error\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            return builder.ToString();
        }

        public string ShowMessage(string content)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"180\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg blank\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            return builder.ToString();
        }

        public string ShowPrompt(string content)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg info\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<center><input type=\"button\" class=\"BigButton\" value=\"返回\" onclick=\"history.back();\"></center>");
            return builder.ToString();
        }

        public string ShowPrompt(string content, string url)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg info\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<center><input type=\"button\" class=\"BigButton\" value=\"返回\" onclick=\"window.location='" + url + "';\"></center>");
            return builder.ToString();
        }

        public string ShowPrompt(string content, string title, string url)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg info\">");
            builder.Append("<h4 class=\"title\">" + title + "</h4><div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<center><input type=\"button\" class=\"BigButton\" value=\"返回\" onclick=\"window.location='" + url + "';\"></center>");
            return builder.ToString();
        }

        public string ShowPromptClose(string content)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg info\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<center><input type=\"button\" class=\"BigButton\" value=\"关闭\" onclick=\"self.close();\"></center>");
            return builder.ToString();
        }

        public string ShowPromptNoNav(string content)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg info\">");
            builder.Append("<div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            return builder.ToString();
        }

        public string ShowWarning(string content, string url)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<br><table class=\"MessageBox\" width=\"300\"  align=\"center\">");
            builder.Append("<tr><td class=\"msg warning\">");
            builder.Append("<h4 class=\"title\">警告</h4><div class=\"content\" style=\"font-size:12pt\">");
            builder.Append(content);
            builder.Append("</div></td></tr>");
            builder.Append("</table>");
            builder.Append("<center><input type=\"button\" class=\"BigButton\" value=\"返回\" onclick=\"window.location='" + url + "';\"></center>");
            return builder.ToString();
        }

        protected virtual void ThemeWrite()
        {
            try
            {
                base.Response.Write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/theme2009/" + new UserCache().Theme.ToString() + "/top.css\">");
            }
            catch (Exception)
            {
                base.Response.Write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/theme/1/style.css\">");
            }
        }

        public SqlConnection Conn
        {
            get
            {
                return this.conn;
            }
        }
    }
}

